using System;
using System.Xml;
namespace Umbraco.Ecommerce.DataControls
{
    /// <summary>
    /// Summary description for UmbracoExtension.
    /// </summary>
    public class UmbracoExtension : umbraco.interfaces.ITree
    {
        private int _id;
        private string _app;

        public int id
        {
            set { _id = value; }
        }
        public string app
        {
            set { _app = value; }
        }

        public void RenderJS(ref System.Text.StringBuilder Javascript)
        {
            Javascript.Append(@"
				function openStoreItem(scriptname) {
				parent.right.document.location.href = 'storeadministration/'+ scriptname;
				}
			");
        }
        public void Render(ref System.Xml.XmlDocument Tree)
        {
            XmlNode root = Tree.DocumentElement;
            XmlElement treeElement = Tree.CreateElement("tree");

            treeElement.SetAttribute("nodeID", "-3322");
            treeElement.SetAttribute("menu", "");
            treeElement.SetAttribute("text", "Unconfirmed orders");
            treeElement.SetAttribute("action", "javascript:openStoreItem('unConfirmedOrders.aspx');");
            treeElement.SetAttribute("src", "");
            treeElement.SetAttribute("icon", "settingDataType.gif");
            treeElement.SetAttribute("openIcon", "settingDataType.gif");
            treeElement.SetAttribute("nodeType", "currentorders");
            root.AppendChild(treeElement);

            treeElement = Tree.CreateElement("tree");
            treeElement.SetAttribute("nodeID", "-3434");
            treeElement.SetAttribute("menu", "");
            treeElement.SetAttribute("text", "Confirmed orders (pending)");
            treeElement.SetAttribute("action", "javascript:openStoreItem('openOrders.aspx');");
            treeElement.SetAttribute("src", "");
            treeElement.SetAttribute("icon", "settingDataType.gif");
            treeElement.SetAttribute("openIcon", "settingDataType.gif");
            treeElement.SetAttribute("nodeType", "currentorders");
            root.AppendChild(treeElement);

            treeElement = Tree.CreateElement("tree");
            treeElement.SetAttribute("nodeID", "-3223");
            treeElement.SetAttribute("menu", "");
            treeElement.SetAttribute("text", "Accepted orders");
            treeElement.SetAttribute("action", "javascript:openStoreItem('acceptedorders.aspx');");
            treeElement.SetAttribute("src", "");
            treeElement.SetAttribute("icon", "settingDataType.gif");
            treeElement.SetAttribute("openIcon", "settingDataType.gif");
            treeElement.SetAttribute("nodeType", "acceptedorders");
            root.AppendChild(treeElement);

            treeElement = Tree.CreateElement("tree");
            treeElement.SetAttribute("nodeID", "-3222");
            treeElement.SetAttribute("menu", "");
            treeElement.SetAttribute("text", "Rejected orders");
            treeElement.SetAttribute("action", "javascript:openStoreItem('cancelledorders.aspx');");
            treeElement.SetAttribute("src", "");
            treeElement.SetAttribute("icon", "settingDataType.gif");
            treeElement.SetAttribute("openIcon", "settingDataType.gif");
            treeElement.SetAttribute("nodeType", "rejectedorders");
            root.AppendChild(treeElement);

            treeElement = Tree.CreateElement("tree");
            treeElement.SetAttribute("nodeID", "-3225");
            treeElement.SetAttribute("menu", "");
            treeElement.SetAttribute("text", "E-shop konfiguration");
            treeElement.SetAttribute("action", "javascript:openStoreItem('configuration.aspx');");
            treeElement.SetAttribute("src", "");
            treeElement.SetAttribute("icon", "folder.gif");
            treeElement.SetAttribute("openIcon", "folder.gif");
            treeElement.SetAttribute("nodeType", "rejectedorders");
            root.AppendChild(treeElement);
        }

        public UmbracoExtension()
        {

        }

        public void ensureDb()
        {
            // "INSERT INTO umbracoApp (appAlias, appIcon, appName, appInitWithTreeAlias) VALUES     ('store', 'store.gif', 'E-shop', 'store')"
            // "INSERT INTO umbracoAppTree (treeInitialize, treeSortOrder, appAlias, treeAlias, treeTitle, treeIconClosed, treeIconOpen, treeHandlerAssembly, treeHandlerType) VALUES     (1, 1, 'store', 'store', 'E-Shop', 'folder.gif', 'folder_o.gif', 'store', 'UmbracoExtension')"
        }
    }
}
